package ns2;

import java.io.Serializable;
import java.util.Scanner;

import util.SSIDException;

/**
 * @author chenhao
 * 
 */
public class Trace implements Serializable {

	private static final long serialVersionUID = 112L;

	/**
	 * The event type. It is given by one of four possible symbols r, +, -, d
	 * which correspond respectively to receive (at the output of the link),
	 * enqueued, dequeued and dropped
	 */
	public Event_Type event;

	/**
	 * The time at which the events occurs
	 */
	public float time;

	/**
	 * The input node of the link at which the events occurs
	 */
	public Node fm_node;

	/**
	 * The output node of the link at which the events occurs
	 */
	public Node to_node;

	/**
	 * The packet type (for example, CBR, or TCP. The type corresponds to the
	 * name that we gave to those application)
	 */
	public Pkt_Type pkt_type;

	/**
	 * The packet size
	 */
	public long pkt_size;

	/**
	 * Some flags
	 */
	public String flags;

	/**
	 * The flow id (fid) of IPv6 that a user can set for each flow at the input
	 * OTcl script
	 */
	public int flowID;

	/**
	 * The source address given in the form of "node.port"
	 */
	public Address src_addr;

	/**
	 * The destination address given in the form of "node.port"
	 */
	public Address dst_addr;

	/**
	 * The network layer protocol's packet sequence number
	 */
	public long seq_num;

	/**
	 * The unique id of the packet
	 */
	public long pkt_id;

	public String reference;

	public Trace(String record) throws SSIDException {
		Scanner scanner = new Scanner(record);
		scanner.useDelimiter(" ");
		this.event = Event_Type.check(scanner.next());
		this.time = scanner.nextFloat();
		this.fm_node = new Node(scanner.nextInt());
		this.to_node = new Node(scanner.nextInt());
		this.pkt_type = Pkt_Type.check(scanner.next());
		this.pkt_size = scanner.nextLong();
		this.flags = scanner.next();
		this.flowID = scanner.nextInt();
		this.src_addr = new Address(scanner.next());
		this.dst_addr = new Address(scanner.next());
		this.seq_num = scanner.nextLong();
		this.pkt_id = scanner.nextLong();
		this.reference = record;
	}

}
